package com.ruoyi.web.controller.students;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.student.domain.StudentsColleges;
import com.ruoyi.student.service.IStudentsCollegesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二级学院信息Controller
 *
 *
 * @date 2024-04-16
 */
@RestController
@RequestMapping("/students/colleges")
public class StudentsCollegesController extends BaseController
{
    @Autowired
    private IStudentsCollegesService studentsCollegesService;

    /**
     * 查询二级学院信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentsColleges studentsColleges)
    {
        startPage();
        List<StudentsColleges> list = studentsCollegesService.selectStudentsCollegesList(studentsColleges);
        return getDataTable(list);
    }

    /**
     * 导出二级学院信息列表
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:export')")
    @Log(title = "二级学院信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentsColleges studentsColleges)
    {
        List<StudentsColleges> list = studentsCollegesService.selectStudentsCollegesList(studentsColleges);
        ExcelUtil<StudentsColleges> util = new ExcelUtil<StudentsColleges>(StudentsColleges.class);
        util.exportExcel(response, list, "二级学院信息数据");
    }

    /**
     * 获取二级学院信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:query')")
    @GetMapping(value = "/{collegeId}")
    public AjaxResult getInfo(@PathVariable("collegeId") Long collegeId)
    {
        return success(studentsCollegesService.selectStudentsCollegesByCollegeId(collegeId));
    }

    /**
     * 新增二级学院信息
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:add')")
    @Log(title = "二级学院信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentsColleges studentsColleges)
    {
        return toAjax(studentsCollegesService.insertStudentsColleges(studentsColleges));
    }

    /**
     * 修改二级学院信息
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:edit')")
    @Log(title = "二级学院信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentsColleges studentsColleges)
    {
        return toAjax(studentsCollegesService.updateStudentsColleges(studentsColleges));
    }

    /**
     * 删除二级学院信息
     */
    @PreAuthorize("@ss.hasPermi('students:colleges:remove')")
    @Log(title = "二级学院信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{collegeIds}")
    public AjaxResult remove(@PathVariable Long[] collegeIds)
    {
        return toAjax(studentsCollegesService.deleteStudentsCollegesByCollegeIds(collegeIds));
    }
}
